Input and Output

  • print
  • input

print


In [1]:
print('Hello world')


Hello world

In [2]:
str = 'Hello World!'
print(str)


Hello World!

In [3]:
from random import choice

a = choice(range(1000))
b = choice(range(1000))

In [4]:
print('{} plus {} is: {}'.format(a, b, a + b))


415 plus 446 is: 861

In [5]:
print('{1} plus {0} is: {2}'.format(a, b, a + b))


446 plus 415 is: 861

In [6]:
print('{0:3} plus {1:3} is: {2:3}'.format(a, b, a + b))


415 plus 446 is: 861

In [7]:
print('{:6} plus {:6} is: {:6}'.format(a, b, a + b))


   415 plus    446 is:    861

In [8]:
print('{:06.2f} plus {:08.2f} is: {:7.2f}'.format(a/2, b/2, a + b))


207.50 plus 00223.00 is:  861.00

In [9]:
print('{} is {}'.format(a, 'odd' if a % 2 else 'even'))


415 is odd

In [10]:
statement = 'name: {}, email: {}, #phone: {}'

values = {'name': 'Arthur king of the britons', 'email': 'king.arthur@britons', 'phone': '(42) 232323'}

print(statement.format(
    values['name'],
    values['email'],
    values['phone']
))


name: Arthur king of the britons, email: king.arthur@britons, #phone: (42) 232323

input


In [11]:
a = input()


This is a test

In [12]:
a = input()
type(a)


This is a test
Out[12]:
str

In [13]:
a = input('Digit a positive number: ')
type(a)


Digit a positive number: 42
Out[13]:
str

In [14]:
a = int(input('Digit an integer '))
b = int(input('Digit another integer '))

print('{} plus {} is: {}'.format(a, b, a + b))


Digit an integer 42
Digit another integer 23
42 plus 23 is: 65